import tkinter as tk
from tkinter import filedialog, messagebox
from datetime import datetime
from PIL import Image, ImageTk
from tkcalendar import DateEntry
import json
import os

from logic import *
from ui import *
def main():

    DATA_FILE = "tasks.json"

    window = tk.Tk()
    window.title("To Do List")
    window.geometry("800x600")
    columns = ["To_Do", "In Progress", "Done"]
    frames = {}



# 创建列框架
    for col in columns:
        frame = tk.Frame(window, relief=tk.RAISED, borderwidth=1)
        frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
        frames[col] = frame
        label = tk.Label(frame, text=col, bg='lightblue', font=('Arial', 12, 'bold'))
        label.pack(fill=tk.X)

# 全局变量，用于追踪被拖动的卡片
    dragged_card = None
    drag_data = {"x": 0, "y": 0}

    tasks_data = load_data()
    for task in tasks_data:
        create_card(frames["To_Do"], task['name'], task['priority'], task['due_date'], task['image_path'],window,columns,frames,DATA_FILE)

# 添加卡片按钮
    button = tk.Button(window, text="Create", command=lambda:create_card_dialog(window,columns,frames,DATA_FILE))
    button.pack()
    window.protocol("WM_DELETE_WINDOW", lambda:on_closing(window,columns,frames,DATA_FILE))

# 运行主循环
    window.mainloop()
    

if __name__ == "__main__":
    main()